๐งช Kubernetes Hands-On Guide (Beginner Friendly)
Part 1 โ Setup
Step 1 โ Start Docker Desktopโ
๐ฏ Why
Kubernetes in our lab runs inside Docker Desktop. If Docker is not running, Kubernetes will not work.
๐ Do
Open Docker Desktop and ensure it is running.
โ Expected
Dashboard loads normally.
๐ง Understand
Docker Desktop provides:
- Container runtime
- Kubernetes cluster (single node)
Step 2 โ Enable Kubernetesโ
๐ฏ Why
Kubernetes must be enabled before we use kubectl.
๐ Do
- Docker Desktop โ Settings
- Kubernetes
- Enable Kubernetes
- Apply & Restart
- Wait until status shows Running
โ Expected
Green status / Running.
๐ง Understand
You now have a single-node Kubernetes cluster on your laptop.
Step 3 โ Verify Kubernetes CLIโ
๐ฏ Why
We use kubectl to talk to Kubernetes.
๐ Do
kubectl version --client
โ Expected
Client version shown.
Step 4 โ Check cluster connectionโ
๐ฏ Why
Make sure kubectl is connected to correct cluster.
๐ Do
kubectl config current-context
โ Expected
Shows docker-desktop
Step 5 โ Check Nodeโ
๐ฏ Why
Node = machine where pods run.
๐ Do
kubectl get nodes
โ Expected
1 node with status Ready.
๐ง Understand
Your laptop is acting as the Kubernetes node.
Part 2 โ Pods
Step 6 โ Create a Podโ
๐ฏ Why
Pod is the smallest unit Kubernetes runs. Usually 1 pod = 1 container.
๐ Do
kubectl run nginx-pod --image=nginx
Step 7 โ Check Pod Statusโ
๐ Do
kubectl get pods
โ Expected
nginx-pod โ Running
๐ง Understand
Kubernetes:
- Pulled nginx image
- Created container
- Assigned IP
- Started it
Step 8 โ Inspect Podโ
๐ฏ Why
See detailed information.
๐ Do
kubectl describe pod nginx-pod
Look at:
- Image
- Status
- Events
Step 9 โ View Logsโ
๐ฏ Why
Logs help debug.
๐ Do
kubectl logs nginx-pod
Step 10 โ Delete Podโ
๐ฏ Why
Plain pod is NOT self-healing.
๐ Do
kubectl delete pod nginx-pod
Check:
kubectl get pods
โ Pod is gone permanently.
๐ง Understand
Pods alone are not managed.
Part 3 โ Deployment (Real Usage)
Step 11 โ Create Deploymentโ
๐ฏ Why
Deployment manages pods:
- Self-healing
- Scaling
- Rolling updates
๐ Do
kubectl create deployment demo --image=nginx
Step 12 โ Verify Deploymentโ
kubectl get deployments
kubectl get pods
โ 1 deployment โ 1 pod (random name)
Step 13 โ Self Healing Testโ
๐ฏ Why
Deployment keeps desired state.
๐ Do
Delete the pod:
kubectl delete pod <pod-name>
Check:
kubectl get pods
โ New pod appears automatically.
๐ง Understand
Deployment enforces:
"I want 1 pod always running."
Step 14 โ Scaleโ
๐ฏ Why
Run multiple copies for load.
๐ Do
kubectl scale deployment demo --replicas=3
Check:
kubectl get pods
โ 3 pods running.
๐ง Understand
Kubernetes handles scaling automatically.
Part 4 โ Service (Networking)
Step 15 โ Expose Deploymentโ
๐ฏ Why
Pods change names/IPs. Service provides stable access.
๐ Do
kubectl expose deployment demo --type=NodePort --port=80
Step 16 โ Check Serviceโ
kubectl get services
Look at:
80:3xxxx/TCP
Open in browser:
http://localhost:<NodePort>
โ Nginx page loads.
๐ง Understand
Service:
- Stable IP
- Load balances to 3 pods
Part 5 โ Labels
Step 17 โ View Labelsโ
๐ฏ Why
Labels connect objects.
๐ Do
kubectl get pods --show-labels
Youโll see something like:
app=demo
Step 18 โ Add Label to Deploymentโ
kubectl label deployment demo team=devops
Check:
kubectl get deployment demo --show-labels
๐ง Understand
This labels the deployment object only.
Step 19 โ Add Label to Pod Template (Permanent)โ
kubectl edit deployment demo
Find:
spec:
template:
metadata:
labels:
Add:
env: training
Save.
Check:
kubectl get pods --show-labels
โ
Pods now have env=training
๐ง Understand
Service selectors match pod labels only.
Step 20 โ Filter Using Labelsโ
kubectl get pods -l env=training
Only matching pods show.
Step 21 โ Remove Label from Podโ
kubectl label pod <pod-name> env-
๐ง Temporary if deployment recreates pod.
Part 6 โ Cleanup
Step 22 โ Delete Everythingโ
kubectl delete service demo
kubectl delete deployment demo
Verify:
kubectl get all
Cluster clean.
Final Concepts Students Should Know
| Object | Purpose |
|---|---|
| Node | Machine |
| Pod | Runs container |
| Deployment | Manages pods |
| Replica | Number of pod copies |
| Service | Networking & load balance |
| Label | Identifies objects |
| Selector | Matches labels |